/*
 * Ethan Levine
 * 
 * The contents of this file are subject to the GNU General Public
 * License (GPL) v2.  The full contents of this license can be
 * found at Mathma's website, http://www.codeplex.com/mathma/license
 */

package mathma.core.expr;

import mathma.core.value.Value;

import java.util.Map;
import java.util.HashMap;

/**
 * @since 0.1.0
 * @author Ethan Levine
 */
public class VariableMapping<E extends Value> {

    Map<Variable<E>, Expression<E>> mapping;
    
    public VariableMapping() {
        mapping = new HashMap<Variable<E>, Expression<E>>();
    }
    
    public VariableMapping(Variable<E> var, Expression<E> expr)
    {
        mapping = new HashMap<Variable<E>, Expression<E>>();
        addMapping(var, expr);
    }
    
    public void addMapping(Variable<E> var, Expression<E> expr) {
        mapping.put(var, expr);
    }
    
    public Expression<E> mapVariable(Variable<E> var) {
        if (mapping.containsKey(var)) {
            return mapping.get(var);
        } else {
            return var;
        }
    }
}
